﻿<%@ taglib uri="/mytaglib" prefix="ct"%>
<%@ include file="/includes.jsp"%>
<script>
	$(document).ready(function() {
		$(":checkbox").click(function(event) {
			event.stopPropagation();//阻止冒泡事件，上级的单击事件不会被调用
		});

	});

	function changeCheck(permissionId) {
		$("#" + permissionId).click();
	}

	function toggleAll() {
		$(":checkbox").prop("checked", $("#allClickTag").is(':checked'));
	}

	function toRoleList() {
		mySubmit('', '/role/list');
	}

	function checkParent(obj, parentId, selectSub) {

		if (selectSub) {
			if (obj.checked) {
				if (parentId != null && !$("#permissionId" + parentId).checked) {
					var parentObj = $("#permissionId" + parentId);
					checkParent(parentObj[0], parentObj.attr("parentId"));
				}
				if (selectSub) {
					$("[parentId=" + obj.value + "]").prop("checked", true);
				}
			} else {
				$("[parentId=" + obj.value + "]").prop("checked", false);
			}
			for (var i = 0; i < $("[parentId=" + obj.value + "]").size(); i++) {
				checkParent($("[parentId=" + obj.value + "]")[i], null, true);
			}
		} else {
			obj.checked = true;
			var parentObj = $("#permissionId" + parentId);
			if (parentObj.attr("parentId")) {
				checkParent(parentObj[0], parentObj.attr("parentId"));
			} else if(!(typeof(parentObj[0]) == "undefined")){
				parentObj[0].checked = true;
			}
		}
	}

	function saveRolePermisson() {
		myAjaxSumbmit('configPermissonForm', '/role/ajax/saveRolePermissions',
				'', function() {

				});
	}
</script>



<div class="box-header">
	<h3 class="box-title">分配权限</h3>
	<div class="box-tools">
		<button type="button" onclick="toRoleList()" class="btn btn-flat">返回</button>
		<button type="button" onclick="saveRolePermisson()" class="btn btn-primary btn-flat">保存</button>
	</div>
</div>
<!-- /.box-header -->
<div class="box-body table-responsive no-padding">
	<form id="configPermissonForm">
		<input type="hidden" id="roleId" name="roleId" value="${roleId}">
		<ct:configPermissionTableTag rpSet="${rpSet}" />
	</form>
</div>
<!-- /.box-body -->